package com.show.mytest;

import java.io.FileInputStream;
import java.io.FileReader;
import java.io.InputStreamReader;

public class Test04_InputStreamReader {
    public static void main(String[] args) throws Exception {
        // 创建字符输入流对象
        FileReader fr = new FileReader("F:/show.txt");
        // 创建字符数组
        char[] buf = new char[1024];
        // 创建长度对象
        int len = -1;
        // 若不为-1,读入字符
        while ((len = fr.read(buf)) != -1){
            // 输出字符数组并转换为字符串
            System.out.println(new String(buf,0,len));  //  	�Һ�˧ ��! 乱码
        }
        // 创建文件转换输入流
        InputStreamReader isr = new InputStreamReader(new FileInputStream("F:/show.txt"),"GBK");
        // 读取文件
        while ((len = isr.read(buf)) != -1){
            System.out.println(new String(buf,0,len));
        }
    }
}
